package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        System.out.println("hello");
        //曾经的我们
        //User user = new User();  //缺点：写死了换个别的类就要改代码
        //user.sayHello();



        //前段时间的我们：学会了反射
        Class cls = Class.forName("demo1.User");//好处
        User obj = (User)cls.newInstance();//缺点：写以大堆反射代码
        obj.sayHello();

        //如今的我们：Spring
        AnnotationConfigApplicationContext ctx
                = new AnnotationConfigApplicationContext("demo1");
        User user2 = ctx.getBean(User.class);
        user2.sayHello();
    }


}
